Skip to content

fix(compiler): Improved type inference for concat operator #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

orisano
Copy link
Contributor

@orisano orisano commented Sep 16, 2023

close #2734

Fixed sqlite engine treating "||" as OR.
MySQL does not have a concat operator, so there is no need to support it.

close sqlc-dev#2734

Fixed sqlite engine treating "||" as OR.
MySQL does not have a concat operator, so there is no need to support it.
@andrewmbenton
Copy link
Collaborator

This might be a bigger issue that we need to handle in a separate PR, but based on my reading of the SQLite docs and experimenting with a running PostgreSQL database it appears the the string concat operator (and I think all operators) will return NULL if any of the inputs is null.

From https://www.sqlite.org/lang_expr.html:

The result of any binary operator is either a numeric value or NULL, except for the || concatenation operator,
and the -> and ->> extract operators which evaluate to either NULL or a text value.

All operators generally evaluate to NULL when any operand is NULL, with specific exceptions as stated below.
This is in accordance with the SQL92 standard.

So I guess I would expect sqlc to output nullable types for outputs, but that should perhaps be addressed for all operators in a new PR.

@orisano orisano closed this Sep 25, 2023
@andrewmbenton
Copy link
Collaborator

@orisano I didn't mean to imply that we should close this. It might be the correct first step to at least fix the treatment of || to make it equivalent to other binary operators. And then we could create a new issue for nullability of all binary operators. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sqlc >= v1.18.0 detects a string concatenation as sql.NullBool
2 participants